
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

public class AboutScreen extends GameCanvas implements Runnable, CommandListener {

    private int delay = 100;
    private Image backGround;
    private Graphics g;
    private boolean isActive;
    private Main iMain;
    private MenuScreen menuScreen;
    private Command cmdBack;
    private Player clickSound;

    public AboutScreen(Main aMain, MenuScreen aMenu) {
        super(true);
        setFullScreenMode(true);
        iMain = aMain;
        menuScreen = aMenu;

        cmdBack = new Command("Back", Command.EXIT, 0);
        this.addCommand(cmdBack);
        setCommandListener(this);
        try {
            //moveSound = Manager.c
            InputStream in2 = getClass().getResourceAsStream("/click.wav");
            clickSound = Manager.createPlayer(in2, "audio/x-wav");
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (MediaException ex) {
            ex.printStackTrace();
        }
    }

    public void Start() {
        try {
            backGround = Image.createImage("about.png");
            iMain = new Main();

        } catch (Exception e) {
        };

        isActive = true;
        Thread t = new Thread(this);
        t.start();
    }

    public void run() {
        while (isActive) {
            Draw();
            flushGraphics();
            try {
                Thread.sleep(delay);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    public void Draw() {
        this.g = this.getGraphics();

        g.drawImage(backGround, 0, 0, Graphics.LEFT | Graphics.TOP);
        this.flushGraphics();
    }

    public void commandAction(Command command, Displayable displayable) {
        if (command == cmdBack) {
            if (OptionScreen.getChon() == 1) {
                try {
                    clickSound.start();
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
            }
            Display.getDisplay(iMain).setCurrent(menuScreen);
            stop();
        }
    }

    public void stop() {
        isActive = false;
    }
}
